#ifndef SCENARIOTREEVIEW_H
#define SCENARIOTREEVIEW_H

#include <QtGui/QMainWindow>
#include <QtGui/QMenu>
#include <QtGui/QDropEvent>
#include <QtCore/QString>
#include <QtCore/QFile>
#include "mainwindowstatmake.h"
#include "connect_thread.h"
#include "statdata.h"
#include <vector>
//#include "comm_base.h"
typedef struct settings_gl	//for future load from file settings
{
	QColor recieved_protocol_color;//-
	QColor send_protocol_color;//-
	QColor change_mode_protocol_color;//-

	QString com_port_name;
	int com_port_baudrate; 
	int com_port_thread_read_interval;
	int com_port_read_write_winapi_timeout;
	QString last_open_data_dir;
	int main_window_width;
	int main_window_height;



	void SettingsFromDisc(QString filename);
	void SettingsToDisc(QString filename);

} settings_gl;

typedef struct main_state
{
	bool is_com_thread_connected;
	void Init(){is_com_thread_connected=false;};
}main_state;

class statmake_window  :public QMainWindow, public Ui::MainWindow{
    Q_OBJECT
public:
	statmake_window(QWidget *parent = 0);
	void Create();
	~statmake_window(){};
	//thread ets support
	commp_thread * main_conn_thread;
	QThread  thr1;

	//old func
	void SaveMainSettingsToFile(QString filename);
	void LoadMainSettingsFromFile(QString filename);
	//new func now data is separated from gui
	void SettingsToInterface(settings_gl sdata);
	void SettingsFromInterface(settings_gl sdata, bool is_savesize);

	void writeparced_vallisttodata(statdatael &elem,QStringList parcedlist);
	settings_gl main_settings;
	main_state main_data;
	QFile protocol_file;
	QString separator;//separator in 53 byte string
		//thread support end
protected:
	int extraidindex;
	std::vector<bool> sort_vect;
	statdataarray mainstatdata;
	int uniq_id_recieved;
	int uniq_id_redone;
	void UpdateTableFromData(bool isindxloaded);
	void UpdateLineFromData(int lineid,statdatael &data);
	//void UpdateLineFromData(statdatael * data,int lineid);
	//do not update cells on program changes
	bool is_manual_cell_change_active;
	//bool is_second_thread_slots_connected;
   // void changeEvent(QEvent *e);
    //void contextMenuEvent(QContextMenuEvent *e);

	void SetLabelForeColor(QLabel * in_label,int qt_color_id);


void SendProtocolMessage(QString message);
private slots:
	//void OnHideFrame2Click();
	void OnLoadStatDataClick();
	void TWcellEdited(int row, int col);
	void THsectionClicked(int id);
	void savetableckicked();
	void testclicked();
	void OnGetStringFromCommThread(QString recieved_string);
	void ParseIncomingStringToData(QString recieved_string);
	void ParseIncomingStringToDataNew(QString recieved_string);
	void RemoveIdClick();
	void OnFailedToConnect();
	void OnConnectionLost();
	
private:

	public slots:
void OnConnectThread();
signals:
void SendForceTimer();
void SendStopConnection();
};

#endif // SCENARIOTREEVIEW_H